package com.jincp.common.http.okhttp;


import com.jincp.common.http.IHttpCallback;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Response;

/**
 * Created by lidongyang on 2016/5/11.
 */
public class ProgressResponseInterceptor implements Interceptor {

    private IHttpCallback callback;

    public ProgressResponseInterceptor(IHttpCallback callback) {
        this.callback = callback;
    }

    @Override
    public Response intercept(Chain chain) throws IOException {
        //拦截
        Response originalResponse = chain.proceed(chain.request());
        //包装响应体并返回
        return originalResponse.newBuilder()
                .body(new ProgressResponseBody(originalResponse.body(), callback))
                .build();
    }
}
